home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / dofile21.lha / dofile / dofile.rexx < prev   
Encoding:
OS/2 REXX Batch file  |  1996-02-23  |  2.8 KB  |  109 lines

  1. /*
  2. ** $VER: dofile.rexx 2.1 (4.2.96) Rolf Rotvel
  3. **
  4. ** Uses datatypes.library & rexxreqtools.library
  5. */
  6.  
  7. cfgfile = 'env:dofile.prefs'                    /* Path to prefs file */
  8. defdir = 'txt:'                                 /* Defdir for filerequester */
  9. multicmd = 'sys:utilities/multiview screen'     /* Path (& options) to Multiview */
  10.  
  11. /*
  12. ** End cfg.
  13. */
  14.  
  15. /* Load libraries */
  16. call addlib('rexxsupport.library', 0, -30, 0)
  17. call addlib('rexxreqtools.library', 0, -30, 0)
  18. call addlib('datatypes.library', 0, -30)
  19.  
  20. /* Get version info from $VER line */
  21. version = subword(sourceline(2), 3, 2) 
  22. /* Check defdir */
  23. if defdir = '' | ~exists(defdir) then defdir = pragma('d')
  24.  
  25. /* Open cfgfile - exit if fail - read it otherwise */
  26. if ~open('tmp', cfgfile, 'r') then do
  27.     call rtezrequest('Couldn''t open '||cfgfile,, version)
  28.     exit 10
  29. end
  30. cfg = upper(' '||translate(readch('tmp', 65535), '', '0a'x))
  31. call close('tmp')
  32.  
  33. /* If no arg then open filerequester */
  34. if arg() = 0 then txt = gettxt(defdir)
  35. else do 
  36.     /* Get args and remove quotes - if any */
  37.     txt = strip(arg(1), 'b', '"')
  38.     /* Handle special cases (File = .info or file = dir) */
  39.     select
  40.         when ~exists(txt) then txt = txt||'.info'
  41.         when word(statef(txt), 1) = 'DIR' then txt = gettxt(txt)
  42.         otherwise nop
  43.     end
  44. end
  45.  
  46. txt = upper(txt)
  47.  
  48. /* Simple error handling */
  49. if ~exists(txt) then exit 10
  50. if word(statef(txt), 2) = 0 then exit 10
  51.  
  52. /* Get (data)type of file */
  53. type = upper(filetype(txt))
  54.  
  55. /* Check ascii & binary files for special cases */
  56. if type = 'ASCII' | type = 'BINARY' then do
  57.     name = getname(txt)
  58.     parse upper var name base '.' suff
  59.     /* Filename has an extension */
  60.     if suff ~= '' then do
  61.         /* We found a match in cfg file */
  62.         if pos(' .'||suff||' ', cfg) > 0 then type = '.'||suff
  63.         /* No match -> check binary files for MOD. type names */
  64.         if type = 'BINARY' then do
  65.             if pos(' '||base||'. ', cfg) > 0 then type = base||'.'
  66.         end
  67.     end
  68. end
  69.  
  70. /* Didn't find any file to process? */
  71. if type = 'BINARY' then do
  72.     /* Check for binary entry in cfg file */
  73.     if pos(' '||type||' ', cfg) = 0 then do
  74.         call rtezrequest('Couldn''t process:'||'0a'x||txt,, version)
  75.         exit
  76.     end
  77. end
  78.  
  79.  
  80. /* Find the cmd associated with the filetype and do it */
  81. type = ' '||type||' '
  82. parse var cfg . (type) '"' cmd '"' .
  83. /* Fall back on Multiview */
  84. if cmd = '' then cmd = upper(multicmd)
  85. say strip(type)||' -> '||cmd
  86.  
  87. /* Do it! */
  88. signal on failure
  89. address command cmd '"'||txt||'"'
  90. exit
  91.  
  92.  
  93. GETTXT:
  94. parse arg dir
  95. txt = rtfilerequest(dir,, version,, 'rt_screentofront=true')
  96. if txt = '' then exit
  97. return strip(txt, 'b', '"')
  98.  
  99. FILETYPE: procedure
  100. parse arg file
  101. return strip(translate(examinedt(file,,), '', '0'x))
  102.  
  103. GETNAME: procedure
  104. parse arg path
  105. return strip(substr(path, max(pos(':', path), lastpos('/', path)) + 1))
  106.  
  107. FAILURE:
  108. exit
  109.